let  mysql = require("mysql");

let connection = mysql.createConnection({host:"127.0.0.1",user:"root",password:"123456",database:"uu"})

connection.connect();

//查询
connection.query("select * from user",(err,data)=>{
    // console.log(err);
    console.log(data);
})

// //新增
let insertSql = "INSERT INTO `user` VALUES (NULL,'李雷','男',34,'2022-12-4','2022-2-4');";
connection.query(insertSql,(err,data)=>{
     console.log("写入新增数据----------------");
    // console.log(err);
    // console.log(data);
    //console.log(data.affectedRows);
})

//删除
let deleteSql = "DELETE FROM user WHERE user_id=3;";
connection.query(deleteSql,(err,data)=>{
    console.log("删除数据--------");
    //console.log(err);
    //console.log(data);
})

//修改
var newtime=new Date().toLocaleString().replace('/','-').replace('/','-');
console.log(newtime);
let updateSql = "UPDATE user set update_time='"+newtime+"' where name='李雷'";
connection.query(updateSql,(err,data)=>{
    console.log("修改数据------");
    //console.log(err);
    //console.log(data);
})
console.log(new Date().toLocaleString().replace('/','-').replace('/','-'))




connection.end();